package com.gadgets.framework.fm03.controller;

import com.gadgets.framework.common.dto.HttpBaseResp;
import com.gadgets.framework.common.dto.Pagination;
import com.gadgets.framework.common.exception.GadgetsException;
import com.gadgets.framework.common.exception.GadgetsServiceException;
import com.gadgets.framework.fm03.dto.BusiFlowOperationDTO;
import com.gadgets.framework.fm03.dto.BusiFlowQueryDTO;
import com.gadgets.framework.fm03.pojo.BusiFlowInfo;
import com.gadgets.framework.fm03.service.IBusiFlowManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author UncleXiu
 * @version V1.0.1
 * @data 2021-01-28
 * @moduel gadgets
 * 
 */
@RestController
@RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/fm03")
public class BusiFlowManagerController {

    @Autowired
    @Qualifier(value = "busiFlowManagerServiceImpl")
    private IBusiFlowManagerService busiFlowManagerService;

    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/addBusiFlow.do")
    public HttpBaseResp<Object> addBusiFlow(HttpServletRequest request, HttpServletResponse response, BusiFlowInfo busiFlowInfo) throws GadgetsServiceException{
        busiFlowManagerService.addBusiFlowInfo(busiFlowInfo);
        return new HttpBaseResp<>();
    }

    /**
     * 条件查询业务流程信息
     * @param request               请求信息
     * @param response              应答信息
     * @param queryDTO              查询条件
     * @param pagination            分页条件
     * @return                      查询结果
     * @throws GadgetsException     异常信息
     */
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "selectBusiFlow.do")
    public HttpBaseResp<BusiFlowInfo> queryBusiFlowInfoByCondition(HttpServletRequest request, HttpServletResponse response, BusiFlowQueryDTO queryDTO, Pagination pagination) throws GadgetsException{
        List<BusiFlowInfo> busiFlowInfos = busiFlowManagerService.queryBusiFlowByCondition(queryDTO, pagination);
        return new HttpBaseResp<>(busiFlowInfos,pagination);
    }

    /**
     * 更新流程状态
     * @param request                       请求信息
     * @param response                      应答信息
     * @param operationDTO                  操作信息
     * @return                              操作结果
     * @throws GadgetsServiceException      异常信息
     */
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "changeFlowStatus.do")
    public HttpBaseResp<Object> changeBusiFlowStatus(HttpServletRequest request, HttpServletResponse response, BusiFlowOperationDTO operationDTO) throws GadgetsException{
        busiFlowManagerService.updateBusiFlowStatus(operationDTO);
        return new HttpBaseResp<>();
    }

}
